package com.shycloud.mido.basic.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shycloud.mido.basic.api.entity.BasSubject;
import com.shycloud.mido.basic.api.enums.MessageCodeEnum;
import com.shycloud.mido.basic.service.BasSubjectService;
import com.shycloud.mido.common.core.util.R;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 科目管理 前端控制器
 *
 * @author yyy
 */
@RestController
@AllArgsConstructor
@RequestMapping("/subject")
@Api(value = "subject", description = "科目管理模块")
public class SubjectController {

	private final BasSubjectService basSubjectService;

	/**
	 * 通过ID查询字典信息
	 *
	 * @param id ID
	 * @return 字典信息
	 */
	@GetMapping("/getOne")
	public R getById(@RequestParam("id") Integer id) {
		return new R<>(basSubjectService.getOne(Wrappers
				.<BasSubject>query().lambda()
				.eq(BasSubject::getId, id)));
	}

	/**
	 * 查询科目列表
	 *
	 * @return 科目列表
	 */
	@GetMapping("/getList")
	public R getList() {
		return new R<>(basSubjectService.list());
	}

	@GetMapping("/subjectById")
	public BasSubject subjectById(@RequestParam("id") String id) {
		return basSubjectService.getById(id);
	}

	/**
	 * 查询科目列表
	 *
	 * @return 科目列表
	 */
	@GetMapping("/subjectMap")
	public Map<Integer, String> subjectMap() {
		Map<Integer, String> map =new HashMap<>();
		List<BasSubject> list =basSubjectService.list();
		for(int i =0; i<list.size(); i++){
			map.put(list.get(i).getId(),list.get(i).getName());
		}
		return map;
	}
}
